﻿<cfsilent>
	<cfscript>
	
		event.setArg("pageTitle", "教学运行管理 - 考试安排 - 考试场次起止时间");
		
		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		
		currentTab = event.getArg("TabID", "labCell");
		
		/* 排考可用时间 */
		timeTable = event.getArg("timeTable");
		
		sql = "SELECT 
					a.cellidx, 
					a.time_start, 
					a.time_end 
				FROM t_examcell a
				WHERE 
					a.cellidx > '0' OR a.cellidx < '0' 
				ORDER BY a.cellidx";
		
		queryObj = new query( datasource=application.dnsSlave );
		
		rs_cell = queryObj.execute( sql=sql ).getResult();
		
		target = event.getArg("Target", "FinalExam");
		
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('DEFAULT_EVENT')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">考试安排</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 campus"></i>考试起止时间设置
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix">
				
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labCell">class="active"</cfif> id="labCell" tabTarget="Cell">课程考试安排</span>
						<span <cfif currentTab eq "labTimeSet">class="active"</cfif> id="labTimeSet" tabTarget="TimeSet">设置排考可用时间</span>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
				<div id="Cell" class="tabContent">
					
					<div class="noticeBlock">
						<h3>设置考试场次的起止时间点</h3>
						<p><span class="img icon16x16 message"></span>校内考试同一天最多安排<em>5</em>个场次, 请根据实际情况设置该场次的起止时间</p>
					</div>
					
					<table class="UIEditable">
						<thead>
							<tr>
								<td width="80">场次</td>
								<cfloop from="1" to="5" index="i">
									<td><cfoutput>#mathAdvice.convertExamIdxToChinese(i)#</cfoutput></td>
								</cfloop>
							</tr>
						</thead>
						<tbody>
							<tr class="editRows">
								<td>起止时间</td>
								<cfloop from="1" to="5" index="i">
									<td><a href="<cfoutput>#buildURL('examCell', {Cell=i})#</cfoutput>"><cfoutput>#datetimeAdvice.formatTimeString(rs_cell["time_start"][i], "HH:MI")#</cfoutput> ~ <cfoutput>#datetimeAdvice.formatTimeString(rs_cell["time_end"][i], "HH:MI")#</cfoutput></a></td>
								</cfloop>
							</tr>
						</tbody>
					</table>
					
					<cfif event.isArgDefined("CELL")>
						
						<cfset cellIndex = event.getArg("CELL") />
                                   
                             <cfset sql = "SELECT 
                                                       a.cellidx, 
                                                       a.time_start, 
                                                       a.time_end 
                                                  FROM t_examcell a
                                                  WHERE a.cellidx = :cellIndex " />
                                         
                             <cfset queryObj = new query( datasource=application.dnsSlave )/>
                             <cfset queryObj.addParam( name="cellIndex", value=cellIndex, cfsqltype="cf_sql_char" ) />
                             <cfset rs_examCell = queryObj.execute( sql=sql ).getResult()/>
						
						<cfif rs_examCell.recordCount GT 0 >
						
							<form id="formEdit" onSubmit="javascript:return processVerfiyForm('formEdit');" class="formWrapper" method="post" action="<cfoutput>#buildURL('examCellUpdateDo')#</cfoutput>">
							
								<input type="hidden" name="CellIDX" value="<cfoutput>#rs_examCell.cellidx#</cfoutput>" />
								
								<div class="label">
									<span class="req">*</span><b>场次</b>
									<cfoutput>#mathAdvice.convertExamIdxToChinese(rs_examCell.cellidx)#</cfoutput>
								</div>
								
								<div class="label">
									<span class="req">*</span><b>考试起止时间</b>
									<input name="TimeStart" id="TimeStart" type="text" class="typeTime" verification="time" maxlength="5" value="<cfoutput>#datetimeAdvice.formatTimeString(rs_examCell.time_start, 'HH:MI')#</cfoutput>" />
									至 
									<input name="TimeEnd" id="TimeEnd" type="text" class="typeTime" verification="time" maxlength="5" value="<cfoutput>#datetimeAdvice.formatTimeString(rs_examCell.time_end, 'HH:MI')#</cfoutput>" />
								</div> 
										 
								<div class="lable">
									<input class="button" type="submit" value="更新" />
									<input id="formReset" class="button1" type="reset" value="重设表格" />
								</div>
							</form>
							
							<script language="javascript" type="text/javascript">
								//<![CDATA[
								<!--
								$(document).ready(function() {
									
									$("#TimeStart").mask("99:99");
									$("#TimeEnd").mask("99:99");
								
								});
								// -->
								//]]>
							</script>
							
						</cfif>
						
					</cfif>
					
				</div>
				
				<div id="TimeSet" class="tabContent">
					
					<div class="noticeBlock">
						<div class="operation">
							<a class="uiButton <cfif target eq "FinalExam">uiButtonSpecial</cfif>" href="<cfoutput>#buildURL('examCell', {target='FinalExam', TabID='labTimeSet'})#</cfoutput>"><span class="uiButtonText">期末考试</span></a>
							<a class="uiButton <cfif target eq "HalfExam">uiButtonSpecial</cfif>" href="<cfoutput>#buildURL('examCell', {target='HalfExam', TabID='labTimeSet'})#</cfoutput>"><span class="uiButtonText">半期考试</span></a>
							<a class="uiButton <cfif target eq "DisperseExam">uiButtonSpecial</cfif>" href="<cfoutput>#buildURL('examCell', {target='DisperseExam', TabID='labTimeSet'})#</cfoutput>"><span class="uiButtonText">分散考试</span></a>
							<a class="uiButton <cfif target eq "ResitExam">uiButtonSpecial</cfif>" href="<cfoutput>#buildURL('examCell', {target='ResitExam', TabID='labTimeSet'})#</cfoutput>"><span class="uiButtonText">补考</span></a>
						</div>
						
						<h3>设置考试可用时间</h3>
						<p><span class="img icon16x16 message"></span>为了提高计划自动排考的成功率, 请尽量使用周一至周五所有的可用时间段, 以最大程度的利用教室资源.</p>
						<hr/>
					</div>
					
					<table class="UICourseTable">
						<thead>
							<tr>
								<td colspan="2" width="2%"></td>
								<td width="14%">星期一</td>
								<td width="14%">星期二</td>
								<td width="14%">星期三</td>
								<td width="14%">星期四</td>
								<td width="14%">星期五</td>
								<td width="14%">星期六</td>
								<td width="14%">星期天</td>
							</tr>
						</thead>
						<tbody>
							<cfloop from="1" to="5" index="lec">
							<tr>
								<cfswitch expression="#lec#">
									<cfcase value="1"><td rowspan="2"><cfoutput>#mathAdvice.convertLectureIdxToDayPart(lec)#</cfoutput></td></cfcase>
									<cfcase value="3"><td rowspan="2"><cfoutput>#mathAdvice.convertLectureIdxToDayPart(lec)#</cfoutput></td></cfcase>
									<cfcase value="5"><td rowspan="2"><cfoutput>#mathAdvice.convertLectureIdxToDayPart(lec)#</cfoutput></td></cfcase>
								</cfswitch>
								<td><cfoutput>#mathAdvice.convertExamIdxToChinese(lec)#</cfoutput></td>
								<cfloop from="1" to="7" index="wkday">
								<td id="tbcLEC<cfoutput>#wkday#</cfoutput><cfoutput>#lec#</cfoutput>" class="<cfif timeTable[wkday][lec]>yes<cfelse>no</cfif>">
								<cfif timeTable[wkday][lec]>
									<a id="tbLEC<cfoutput>#wkday#</cfoutput><cfoutput>#lec#</cfoutput>" class="botton yes" href="javascript:tableSet(<cfoutput>#wkday#</cfoutput>,<cfoutput>#lec#</cfoutput>);">可排</a>
									<cfelse>
									<a id="tbLEC<cfoutput>#wkday#</cfoutput><cfoutput>#lec#</cfoutput>" class="botton no" href="javascript:tableSet(<cfoutput>#wkday#</cfoutput>,<cfoutput>#lec#</cfoutput>);">禁用</a>
								</cfif>
								</td>
								</cfloop>
							</tr>
							</cfloop>
						</tbody>
					</table>
					
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						function tableSet(weekDay, lecture){
							
							var $trigger = $("#tbLEC" + weekDay + lecture);
							var $cell = $("#tbcLEC" + weekDay + lecture);
							
							var status = $trigger.hasClass("yes");
							var newStatus = true;
							
							/* 切换状态数据 */
							if (status) {
								newStatus = false;
							}
							
							$.post(
									"<cfoutput>#buildURL('apiTimeTablePropChange')#</cfoutput>", 
									{
										'wkday' : weekDay,
										'lec' : lecture,
										'method' : '<cfoutput>#target#</cfoutput>',
										'status' : newStatus,
										'seed': (new Date()).getTime()
									}, 
									function(data) {
										
										result = $.parseJSON(data);
										
										/* 刷新时间状态数据 */
										
										if (result.<cfoutput>#target#</cfoutput>) { 
											$trigger.text("可排").removeClass("no").addClass("yes"); 
											$cell.removeClass("no").addClass("yes"); 
										} 
										else { 
											$trigger.text("禁用").removeClass("yes").addClass("no"); 
											$cell.removeClass("yes").addClass("no"); 
										}
										
									});
							
						}
						// -->
						//]]>
					</script>
					
				</div>
				
			</div>
		</li>
	</ul>
</div>